package cn.dapeng.base;


/**
 * 1. join()
 * 2. join(long)
 * 3. join(long, int)
 *
 * join() 方法会阻塞当前线程，直到被调用的线程执行完毕
 */
public class Join_t01 {

    private static Thread t1, t2, t3;

    public static void main(String[] args) {

        t1 = new Thread(() -> {
            try {
                t2.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t1 start");
        });

        t2 = new Thread(() -> {
            try {
                t3.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t2 start");
        });

        t3 = new Thread(() -> {
            System.out.println("t3 start");
        });

        t1.start();
        t2.start();
        t3.start();

        try {
            t1.join();
//            t2.join();
//            t3.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("main end");
    }
}
